#!/usr/bin/env julia

"""
Quick test for TongLun.jl basic functionality

This is a lightweight test for rapid development iteration.
For comprehensive testing, use test/runtests.jl
"""

using Test
using TongLun

println("🔍 Testing ComplexF32 support...")

# Test ComplexF32 creation and round-trip
println("1. Testing ComplexF32 round-trip...")
TongLun.export_fn("test.identity", identity)

z32 = ComplexF32(1.5f0, 2.5f0)
println("   Original: $z32 ($(typeof(z32)))")

result = TongLun.call_fn("test.identity", z32)
println("   Result: $result ($(typeof(result)))")

if result isa ComplexF32 && result === z32
    println("   ✅ ComplexF32 round-trip successful")
else
    println("   ❌ ComplexF32 round-trip failed")
end

# Test ComplexF32 operations
println("2. Testing ComplexF32 operations...")
TongLun.export_fn("test.complex_abs", abs)
TongLun.export_fn("test.complex_conj", conj)

abs_result = TongLun.call_fn("test.complex_abs", z32)
println("   abs($z32) = $abs_result ($(typeof(abs_result)))")

conj_result = TongLun.call_fn("test.complex_conj", z32)
println("   conj($z32) = $conj_result ($(typeof(conj_result)))")

if conj_result isa ComplexF32
    println("   ✅ ComplexF32 operations preserve type")
else
    println("   ❌ ComplexF32 operations don't preserve type")
end

# Test real/imag extraction
println("3. Testing real/imag extraction...")
TongLun.export_fn("test.complex_real", real)
TongLun.export_fn("test.complex_imag", imag)

real_result = TongLun.call_fn("test.complex_real", z32)
imag_result = TongLun.call_fn("test.complex_imag", z32)

println("   real($z32) = $real_result ($(typeof(real_result)))")
println("   imag($z32) = $imag_result ($(typeof(imag_result)))")

# Note: These will be Float64 due to TongLun's type system limitations
if real_result ≈ Float64(real(z32)) && imag_result ≈ Float64(imag(z32))
    println("   ✅ Real/imag extraction works (converted to Float64)")
else
    println("   ❌ Real/imag extraction failed")
end

println("✅ ComplexF32 test completed!") 